package com.example.a28796.beautiful.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.bean.FirstPageBean;
import com.example.a28796.beautiful.bean.FirstPageMainBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 28796 on 2016/8/30.
 */
public class FirstPageMainAdapter extends BaseAdapter{
    private List<FirstPageMainBean.ObjBean.ListDataBean> mData;
    private Context mContext;
    public FirstPageMainAdapter(List<FirstPageMainBean.ObjBean.ListDataBean> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }
    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolderTwo holderTwo = null;
                if(convertView==null){
                    convertView = LayoutInflater.from(mContext).inflate(R.layout.item_fragment_first2,null);
                    holderTwo = new ViewHolderTwo(convertView);
                    convertView.setTag(holderTwo);
                }else{
                    holderTwo = (ViewHolderTwo) convertView.getTag();
                }
            final FirstPageMainBean.ObjBean.ListDataBean listDataBean = mData.get(position);
            final String nickname =listDataBean.getUser().getNickname();
            holderTwo.mTextViewName.setText(nickname);
            final String title = listDataBean.getTitle();
            holderTwo.mTextViewTitle.setText(title);
            final FirstPageMainBean.ObjBean.ListDataBean.ArticleGroupNumBean articleGroupNum = listDataBean.getArticleGroupNum();
            final int viewNum = articleGroupNum.getViewNum();
            holderTwo.mTextViewLiulan.setText("评论："+viewNum);
            final int allCommentNum = articleGroupNum.getAllCommentNum();
            holderTwo.mTextViewTalk.setText("浏览："+allCommentNum);
            final List<FirstPageMainBean.ObjBean.ListDataBean.PhotoesBean> photoes = listDataBean.getPhotoes();
        for (int i = 0; i <photoes.size() ; i++) {
            final String url = photoes.get(i).getUrl();
            Picasso.with(mContext).load(url).into(holderTwo.mImageViewLeft);
        }


        return convertView;
    }
    public static class ViewHolderTwo{
        private ImageView mImageViewLeft;
        private TextView mTextViewTitle,mTextViewName,mTextViewTalk,mTextViewLiulan;
        public ViewHolderTwo(View view){
            mImageViewLeft = (ImageView) view.findViewById(R.id.iv_item_first2);
            mTextViewName = (TextView) view.findViewById(R.id.tv_item_first2_name);
            mTextViewTitle = (TextView) view.findViewById(R.id.tv_item_first2_smalltitle);
            mTextViewTalk = (TextView) view.findViewById(R.id.tv_item_first2_talk);
            mTextViewLiulan = (TextView) view.findViewById(R.id.tv_item_first2_liulan);
        }
    }
}
